package app.myproject.util;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailUtil {
	
	public static String ADMINISTRATOR_EMAIL = "mktsang2011@gmail.com";
	
	public static boolean sendEmail(String recipient, String subject, String body) {
		
		if (recipient == null) return false;
		
		try {
			
			Properties props = new Properties();
			Session session = Session.getDefaultInstance(props, null);
			
			Message msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress(ADMINISTRATOR_EMAIL, "Admin"));
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
			msg.setSubject(subject);
			msg.setText(body);
			Transport.send(msg);

		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
}
